﻿using System;
using System.Collections.Generic;
using System.Text;
using MasterDetailTemplate.Views;
using Xamarin.Forms;

namespace MasterDetailTemplate.Services.Implementations {
    /// <summary>
    /// 内容页激活服务。
    /// By WZC
    /// </summary>
    public class ContentPageActivationService : IContentPageActivationService {
        /// <summary>
        /// 页面缓存。
        /// </summary>
        private Dictionary<string, ContentPage> cahe =
            new Dictionary<string, ContentPage>();

        /// <summary>
        /// 激活内容页。
        /// </summary>
        /// <param name="pageKey">页面键。</param>
        public ContentPage Activate(string pageKey) =>
            cahe.ContainsKey(pageKey)
                ? cahe[pageKey]
                : cahe[pageKey] = (ContentPage) Activator.CreateInstance(
                    ContentNavigationConstants.PageKeyTypeDictionary[pageKey]);
    }
}